//
// Created by jinbang.li on 2023/8/6.
//

#include "IOpPlayerBuilder.h"
#include "../Demux/IOpDemux.h"
#include "../Decode/IOpDecode.h"
#include "../Audio/IOpResample.h"
#include "../Audio/IOpAudioPlay.h"
#include "../Video/IOpVideoView.h"

IOpPlayer* IOpPlayerBuilder::BuilderPlayer(unsigned char index) {
    IOpPlayer* player = createPlayer(index);
    IOpDemux* demux = createDemux();

    IOpDecode* vdecode = createDecode();
    IOpDecode* adecode = createDecode();

    demux->addObservers(vdecode);
    demux->addObservers(adecode);

    IOpVideoView* view = createVideoView();
    vdecode->addObservers(view);

    IOpResample* resample = createResample();
    adecode->addObservers(resample);
    IOpAudioPlay* audioPlay = createAudioPlay();
    resample->addObservers(audioPlay);

    player->demux = demux;
    player->adecode = adecode;
    player->vdecode = vdecode;
    player->videoView = view;
    player->resample = resample;
    player->audioPlay = audioPlay;
    return player;
}